package innerInterceptor;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

public class UploadFilesAction extends ActionSupport{
	private File[] file;//代表临时文件，可以使用list
	private String[] fileFileName;//原始名称
	private String[] fileContentType;//原始类型
	
	public String execute(){
		String path=ServletActionContext.getServletContext().getRealPath("/images");
		for (int i = 0; i < file.length; i++) {
			File toSave=new File(path+"/"+fileFileName[i]);
			try {
				BufferedInputStream in = new BufferedInputStream(new FileInputStream(file[i]));
				BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(toSave));
				int b;
				while((b=in.read())!=-1){
					out.write(b);
				}
				in.close();
				out.close();
			} catch (Exception e) {
				e.printStackTrace();
				return "input";
			}
		}
		return "success";
	}
	
	public File[] getFile() {
		return file;
	}
	public String[] getFileFileName() {
		return fileFileName;
	}
	public String[] getFileContentType() {
		return fileContentType;
	}
	public void setFile(File[] file) {
		this.file = file;
	}
	public void setFileFileName(String[] fileFileName) {
		this.fileFileName = fileFileName;
	}
	public void setFileContentType(String[] fileContentType) {
		this.fileContentType = fileContentType;
	}
}
